package com.tair.data.properties;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Properties;
import com.tair.model.Note;

/*
 * property format will be note.id.key = value
 * current values are : title and body
 * 
 * The note loader will return an object of type PropertyNote which extends the abstract class note factory.
 */

public class PropertiesDataLoader extends com.tair.dao.NoteFactory {
	
	public Properties init() {
		Properties props = new Properties();
		try {
			FileInputStream in = new FileInputStream("defaultProperties");
			props.load(in);
			in.close();
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
		return props;
	}
	
	public void saveNote(Note note) {
		
	}
	
	public void getAllNotes() {
		Properties props = init();
		
	}
	
	public Note LoadNote(int i) {
		Properties props = init();
		com.tair.model.Note note = new Note(props.getProperty(titleKey(i)), props.getProperty(bodyKey(i)));
		note.setId(i);
		return note;
	}
	
	public void setTitle(int i, String title) {
		Properties props = init();
		props.setProperty(titleKey(i), title);
	}
	
	public void setBody (int i, String body) {
		Properties props = init();
		props.setProperty(bodyKey(i), body);
	}

	
	public String getTitle(int i) {
		return init().getProperty(titleKey(i));
	}
	
	public String getBody(int i) {
		return init().getProperty(bodyKey(i));
	}
	
	
	public void setIndex(int i, int x) {
		
	}
	
	public int getIndex(int i) {
		return 0;
	}
	
	public String bodyKey(int i) {
		return "Note." + i + ".body";
	}
	
	public String titleKey(int i) {
		return "Note." + i + ".title";
	}
	

}

